package com.cjm.algorithm.leetcode;

/**
 * <a href="https://leetcode.cn/problems/consecutive-characters/">连续字符</a>
 *
 * 给你一个字符串 s ，字符串的「能量」定义为：只包含一种字符的最长非空子字符串的长度。
 *
 * 请你返回字符串 s 的 能量。
 *
 */
public class MaxPower1446 {
    public int maxPower(String s) {
        Character pre = null;
        int num = 0;
        int max = 0;
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char cur = chars[i];
            if (pre == null) {
                pre = cur;
                num++;
                max = 1;
                continue;
            }
            if (cur == pre) {
                num++;
                max = Math.max(num, max);
                continue;
            }
            pre = cur;
            max = Math.max(max, num);
            num = 1;
        }
        return max;
    }

    public static void main(String[] args) {
        MaxPower1446 maxPower1446 = new MaxPower1446();
        System.err.println(maxPower1446.maxPower("leetcode"));
    }
}
